package com.truyen.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.truyen.persistence.dao.UserLikedDao;
import com.truyen.persistence.entity.Account;
import com.truyen.persistence.entity.TruyenTranh;
import com.truyen.persistence.entity.UserLiked;
import com.truyen.service.UserLikedService;
import com.truyen.utils.PagingInfo;


@Service
public class UserLikedServiceImpl implements UserLikedService {
	
	@Autowired
	private UserLikedDao userLikedDao;

	@Override
	public void save(UserLiked entity) {
		userLikedDao.save(entity);
	}

	@Override
	public UserLiked findById(Long id) {
		return userLikedDao.findById(id);
	}

	@Override
	public List<UserLiked> getAll() {
		return userLikedDao.findAll();
	}

	@Transactional
	@Override
	public void delete(long idULiked) {
		try{
			UserLiked u = findById(idULiked);
			if(u != null){
				userLikedDao.delete(u);
			}
		}catch(Exception e){
			
		}
		
	}

	@Override
	public List<UserLiked> getLstByAccountWithPaging(Account account,
			PagingInfo pInfo) {
		return userLikedDao.getLstByAccountWithPaging(account,pInfo);
	}

	@Override
	public UserLiked findByProperty(String column, Object value) {
		List<UserLiked> lst = userLikedDao.findByProperty(column, value);
		return (lst.size() > 0) ? lst.get(0) : null;
	}

	@Override
	public UserLiked findByAccount(Account account, String nameTruyen) {
		return userLikedDao.findByAccount(account, nameTruyen);
	}

}
